package com.stylefeng.guns.modular.journal.controller;

import com.baomidou.mybatisplus.plugins.Page;
import com.stylefeng.guns.common.constant.factory.PageFactory;
import com.stylefeng.guns.common.persistence.model.Journal;
import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.shiro.ShiroKit;
import com.stylefeng.guns.modular.journal.service.IJournalService;
import com.stylefeng.guns.modular.journal.dao.JournalDao;
import com.stylefeng.guns.modular.journal.wapper.JournalWarpper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.Map;

/**
 * 交易流水控制器
 *
 * @author fengshuonan
 * @Date 2018-01-11 11:25:16
 */
@Controller
@RequestMapping("/journal")
public class JournalController extends BaseController {

    private String PREFIX = "/journal/journal/";

    @Autowired
    private IJournalService journalService;

    @Autowired
    private JournalDao journalDao;

    /**
     * 跳转到交易流水首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "journal.html";
    }

    /**
     * 获取交易流水列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(String condition) {

        Page<Journal> page = new PageFactory<Journal>().defaultPage();
        List<Map<String, Object>> result = journalDao.list(page, condition,ShiroKit.getUser().id);
        page.setRecords((List<Journal>) new JournalWarpper(result).warp());
        return super.packForBT(page);
    }

    /**
     * 交易流水详情
     */
    @RequestMapping(value = "/detail/{journalId}")
    @ResponseBody
    public Object detail(@PathVariable("journalId") Integer journalId) {
        return journalService.selectById(journalId);
    }
}
